<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="计件年月" prop="pieceDate">
        <el-input
          v-model="queryParams.pieceDate"
          placeholder="请输入计件年月"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司代码" prop="factoryCode">
        <el-input
          v-model="queryParams.factoryCode"
          placeholder="请输入公司代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hr:pieceWage:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hr:pieceWage:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hr:pieceWage:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hr:pieceWage:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="pieceWageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="计件年月" align="center" prop="pieceDate" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="工号" align="center" prop="jobNo" />
      <el-table-column label="部门" align="center" prop="department" />
      <el-table-column label="分部" align="center" prop="branch" />
      <el-table-column label="组别" align="center" prop="pGroup" />
      <el-table-column label="岗位" align="center" prop="jobs" />
      <el-table-column label="车间" align="center" prop="workshop" />
      <el-table-column label="生产线" align="center" prop="proLine" />
      <el-table-column label="工位代码" align="center" prop="gwCode" />
      <el-table-column label="工位名称" align="center" prop="gwName" />
      <el-table-column label="计件单价" align="center" prop="piecePrice" />
      <el-table-column label="合计完成工作量" align="center" prop="finishTotal" />
      <el-table-column label="计件工资金额" align="center" prop="pieceMoney" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="1日报工数量" align="center" prop="bgNum1" />
      <el-table-column label="2日报工数量" align="center" prop="bgNum2" />
      <el-table-column label="3日报工数量" align="center" prop="bgNum3" />
      <el-table-column label="4日报工数量" align="center" prop="bgNum4" />
      <el-table-column label="5日报工数量" align="center" prop="bgNum5" />
      <el-table-column label="6日报工数量" align="center" prop="bgNum6" />
      <el-table-column label="7日报工数量" align="center" prop="bgNum7" />
      <el-table-column label="8日报工数量" align="center" prop="bgNum8" />
      <el-table-column label="9日报工数量" align="center" prop="bgNum9" />
      <el-table-column label="10日报工数量" align="center" prop="bgNum10" />
      <el-table-column label="11日报工数量" align="center" prop="bgNum11" />
      <el-table-column label="12日报工数量" align="center" prop="bgNum12" />
      <el-table-column label="13日报工数量" align="center" prop="bgNum13" />
      <el-table-column label="14日报工数量" align="center" prop="bgNum14" />
      <el-table-column label="15日报工数量" align="center" prop="bgNum15" />
      <el-table-column label="16日报工数量" align="center" prop="bgNum16" />
      <el-table-column label="17日报工数量" align="center" prop="bgNum17" />
      <el-table-column label="18日报工数量" align="center" prop="bgNum18" />
      <el-table-column label="19日报工数量" align="center" prop="bgNum19" />
      <el-table-column label="20日报工数量" align="center" prop="bgNum20" />
      <el-table-column label="21日报工数量" align="center" prop="bgNum21" />
      <el-table-column label="22日报工数量" align="center" prop="bgNum22" />
      <el-table-column label="23日报工数量" align="center" prop="bgNum23" />
      <el-table-column label="24日报工数量" align="center" prop="bgNum24" />
      <el-table-column label="25日报工数量" align="center" prop="bgNum25" />
      <el-table-column label="26日报工数量" align="center" prop="bgNum26" />
      <el-table-column label="27日报工数量" align="center" prop="bgNum27" />
      <el-table-column label="28日报工数量" align="center" prop="bgNum28" />
      <el-table-column label="29日报工数量" align="center" prop="bgNum29" />
      <el-table-column label="30日报工数量" align="center" prop="bgNum30" />
      <el-table-column label="31日报工数量" align="center" prop="bgNum31" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hr:pieceWage:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hr:pieceWage:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改计件工资核算对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="计件年月" prop="pieceDate">
          <el-input v-model="form.pieceDate" placeholder="请输入计件年月" />
        </el-form-item>
        <el-form-item label="公司代码" prop="factoryCode">
          <el-input v-model="form.factoryCode" placeholder="请输入公司代码" />
        </el-form-item>
        <el-form-item label="公司名称" prop="factoryName">
          <el-input v-model="form.factoryName" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="工号" prop="jobNo">
          <el-input v-model="form.jobNo" placeholder="请输入工号" />
        </el-form-item>
        <el-form-item label="部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入部门" />
        </el-form-item>
        <el-form-item label="分部" prop="branch">
          <el-input v-model="form.branch" placeholder="请输入分部" />
        </el-form-item>
        <el-form-item label="组别" prop="pGroup">
          <el-input v-model="form.pGroup" placeholder="请输入组别" />
        </el-form-item>
        <el-form-item label="岗位" prop="jobs">
          <el-input v-model="form.jobs" placeholder="请输入岗位" />
        </el-form-item>
        <el-form-item label="车间" prop="workshop">
          <el-input v-model="form.workshop" placeholder="请输入车间" />
        </el-form-item>
        <el-form-item label="生产线" prop="proLine">
          <el-input v-model="form.proLine" placeholder="请输入生产线" />
        </el-form-item>
        <el-form-item label="工位代码" prop="gwCode">
          <el-input v-model="form.gwCode" placeholder="请输入工位代码" />
        </el-form-item>
        <el-form-item label="工位名称" prop="gwName">
          <el-input v-model="form.gwName" placeholder="请输入工位名称" />
        </el-form-item>
        <el-form-item label="计件单价" prop="piecePrice">
          <el-input v-model="form.piecePrice" placeholder="请输入计件单价" />
        </el-form-item>
        <el-form-item label="合计完成工作量" prop="finishTotal">
          <el-input v-model="form.finishTotal" placeholder="请输入合计完成工作量" />
        </el-form-item>
        <el-form-item label="计件工资金额" prop="pieceMoney">
          <el-input v-model="form.pieceMoney" placeholder="请输入计件工资金额" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="1日报工数量" prop="bgNum1">
          <el-input v-model="form.bgNum1" placeholder="请输入1日报工数量" />
        </el-form-item>
        <el-form-item label="2日报工数量" prop="bgNum2">
          <el-input v-model="form.bgNum2" placeholder="请输入2日报工数量" />
        </el-form-item>
        <el-form-item label="3日报工数量" prop="bgNum3">
          <el-input v-model="form.bgNum3" placeholder="请输入3日报工数量" />
        </el-form-item>
        <el-form-item label="4日报工数量" prop="bgNum4">
          <el-input v-model="form.bgNum4" placeholder="请输入4日报工数量" />
        </el-form-item>
        <el-form-item label="5日报工数量" prop="bgNum5">
          <el-input v-model="form.bgNum5" placeholder="请输入5日报工数量" />
        </el-form-item>
        <el-form-item label="6日报工数量" prop="bgNum6">
          <el-input v-model="form.bgNum6" placeholder="请输入6日报工数量" />
        </el-form-item>
        <el-form-item label="7日报工数量" prop="bgNum7">
          <el-input v-model="form.bgNum7" placeholder="请输入7日报工数量" />
        </el-form-item>
        <el-form-item label="8日报工数量" prop="bgNum8">
          <el-input v-model="form.bgNum8" placeholder="请输入8日报工数量" />
        </el-form-item>
        <el-form-item label="9日报工数量" prop="bgNum9">
          <el-input v-model="form.bgNum9" placeholder="请输入9日报工数量" />
        </el-form-item>
        <el-form-item label="10日报工数量" prop="bgNum10">
          <el-input v-model="form.bgNum10" placeholder="请输入10日报工数量" />
        </el-form-item>
        <el-form-item label="11日报工数量" prop="bgNum11">
          <el-input v-model="form.bgNum11" placeholder="请输入11日报工数量" />
        </el-form-item>
        <el-form-item label="12日报工数量" prop="bgNum12">
          <el-input v-model="form.bgNum12" placeholder="请输入12日报工数量" />
        </el-form-item>
        <el-form-item label="13日报工数量" prop="bgNum13">
          <el-input v-model="form.bgNum13" placeholder="请输入13日报工数量" />
        </el-form-item>
        <el-form-item label="14日报工数量" prop="bgNum14">
          <el-input v-model="form.bgNum14" placeholder="请输入14日报工数量" />
        </el-form-item>
        <el-form-item label="15日报工数量" prop="bgNum15">
          <el-input v-model="form.bgNum15" placeholder="请输入15日报工数量" />
        </el-form-item>
        <el-form-item label="16日报工数量" prop="bgNum16">
          <el-input v-model="form.bgNum16" placeholder="请输入16日报工数量" />
        </el-form-item>
        <el-form-item label="17日报工数量" prop="bgNum17">
          <el-input v-model="form.bgNum17" placeholder="请输入17日报工数量" />
        </el-form-item>
        <el-form-item label="18日报工数量" prop="bgNum18">
          <el-input v-model="form.bgNum18" placeholder="请输入18日报工数量" />
        </el-form-item>
        <el-form-item label="19日报工数量" prop="bgNum19">
          <el-input v-model="form.bgNum19" placeholder="请输入19日报工数量" />
        </el-form-item>
        <el-form-item label="20日报工数量" prop="bgNum20">
          <el-input v-model="form.bgNum20" placeholder="请输入20日报工数量" />
        </el-form-item>
        <el-form-item label="21日报工数量" prop="bgNum21">
          <el-input v-model="form.bgNum21" placeholder="请输入21日报工数量" />
        </el-form-item>
        <el-form-item label="22日报工数量" prop="bgNum22">
          <el-input v-model="form.bgNum22" placeholder="请输入22日报工数量" />
        </el-form-item>
        <el-form-item label="23日报工数量" prop="bgNum23">
          <el-input v-model="form.bgNum23" placeholder="请输入23日报工数量" />
        </el-form-item>
        <el-form-item label="24日报工数量" prop="bgNum24">
          <el-input v-model="form.bgNum24" placeholder="请输入24日报工数量" />
        </el-form-item>
        <el-form-item label="25日报工数量" prop="bgNum25">
          <el-input v-model="form.bgNum25" placeholder="请输入25日报工数量" />
        </el-form-item>
        <el-form-item label="26日报工数量" prop="bgNum26">
          <el-input v-model="form.bgNum26" placeholder="请输入26日报工数量" />
        </el-form-item>
        <el-form-item label="27日报工数量" prop="bgNum27">
          <el-input v-model="form.bgNum27" placeholder="请输入27日报工数量" />
        </el-form-item>
        <el-form-item label="28日报工数量" prop="bgNum28">
          <el-input v-model="form.bgNum28" placeholder="请输入28日报工数量" />
        </el-form-item>
        <el-form-item label="29日报工数量" prop="bgNum29">
          <el-input v-model="form.bgNum29" placeholder="请输入29日报工数量" />
        </el-form-item>
        <el-form-item label="30日报工数量" prop="bgNum30">
          <el-input v-model="form.bgNum30" placeholder="请输入30日报工数量" />
        </el-form-item>
        <el-form-item label="31日报工数量" prop="bgNum31">
          <el-input v-model="form.bgNum31" placeholder="请输入31日报工数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPieceWage, getPieceWage, delPieceWage, addPieceWage, updatePieceWage } from "@/api/hr/pieceWage";

export default {
  name: "PieceWage",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 计件工资核算表格数据
      pieceWageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pieceDate: null,
        factoryCode: null,
        factoryName: null,
        name: null,
        jobNo: null,
        department: null,
        branch: null,
        pGroup: null,
        jobs: null,
        workshop: null,
        proLine: null,
        gwCode: null,
        gwName: null,
        piecePrice: null,
        finishTotal: null,
        pieceMoney: null,
        bgNum1: null,
        bgNum2: null,
        bgNum3: null,
        bgNum4: null,
        bgNum5: null,
        bgNum6: null,
        bgNum7: null,
        bgNum8: null,
        bgNum9: null,
        bgNum10: null,
        bgNum11: null,
        bgNum12: null,
        bgNum13: null,
        bgNum14: null,
        bgNum15: null,
        bgNum16: null,
        bgNum17: null,
        bgNum18: null,
        bgNum19: null,
        bgNum20: null,
        bgNum21: null,
        bgNum22: null,
        bgNum23: null,
        bgNum24: null,
        bgNum25: null,
        bgNum26: null,
        bgNum27: null,
        bgNum28: null,
        bgNum29: null,
        bgNum30: null,
        bgNum31: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询计件工资核算列表 */
    getList() {
      this.loading = true;
      listPieceWage(this.queryParams).then(response => {
        this.pieceWageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        pieceDate: null,
        factoryCode: null,
        factoryName: null,
        name: null,
        jobNo: null,
        department: null,
        branch: null,
        pGroup: null,
        jobs: null,
        workshop: null,
        proLine: null,
        gwCode: null,
        gwName: null,
        piecePrice: null,
        finishTotal: null,
        pieceMoney: null,
        remark: null,
        bgNum1: null,
        bgNum2: null,
        bgNum3: null,
        bgNum4: null,
        bgNum5: null,
        bgNum6: null,
        bgNum7: null,
        bgNum8: null,
        bgNum9: null,
        bgNum10: null,
        bgNum11: null,
        bgNum12: null,
        bgNum13: null,
        bgNum14: null,
        bgNum15: null,
        bgNum16: null,
        bgNum17: null,
        bgNum18: null,
        bgNum19: null,
        bgNum20: null,
        bgNum21: null,
        bgNum22: null,
        bgNum23: null,
        bgNum24: null,
        bgNum25: null,
        bgNum26: null,
        bgNum27: null,
        bgNum28: null,
        bgNum29: null,
        bgNum30: null,
        bgNum31: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加计件工资核算";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPieceWage(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改计件工资核算";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePieceWage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPieceWage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除计件工资核算编号为"' + ids + '"的数据项？').then(function() {
        return delPieceWage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hr/pieceWage/export', {
        ...this.queryParams
      }, `pieceWage_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
